﻿using Microsoft.AspNetCore.Mvc;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications.Models;
using MiniFox.Resources;
using MiniFox.Utility;
using MiniFox.Web.Infrastructure;
using System.ComponentModel.DataAnnotations;

namespace MiniFox.Platform.Applications.Web
{
    /// <summary>
    /// 
    /// </summary>
    [PublicAccessible, NoCache]
    public class DesktopController : AuthorizedController<IDesktopService>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Response<SystemUser> CurrentUser()
        {
            return this.Component.CurrentSystemUser.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Response<IEnumerable<SystemApp>> Apps()
        {
            var apps = this.Component.GetSystemApps();
            return apps.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<IEnumerable<ITreeNode>> Menu([FromQuery(Name = GlobalKey.APP_ID), Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")] string appId)
        {
            var tree = Component.GetMenu(appId);
            return tree.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<IEnumerable<ITreeNode>> Nav([FromQuery(Name = GlobalKey.APP_ID), Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")] string appId)
        {
            var tree = Component.GetNav(appId);
            var response = tree.CreateResponse();
            return response;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Response<IEnumerable<Shortcut>> Shortcuts()
        {
            var shortcuts = Component.GetShortcuts();
            return shortcuts.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        [HttpPost]
        public Response CreateShortcut([FromBody] SystemNavModule module)
        {

            Response response = new Response();
            if (!Component.CreateShortcut(module))
            {

            }
            return response;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        [HttpPost]
        public Response RemoveShortcut(SystemNavModule module)
        {

            Response response = new Response();
            if (!Component.RemoveShortcut(module))
            {

            }
            return response;
        }

    }
}
